# Test program.
add_executable(valid EXCLUDE_FROM_ALL
    Utils.cc Misc.cc Bundles.cc Services.cc LifeCycle.cc Valid.cc
)
target_link_libraries(valid OSGi++ -lcppunit)
set_target_properties(valid PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${OSGi_BINARY_DIR}/bin
    COMPILE_FLAGS -I/usr/local/include
    LINK_FLAGS    -L/usr/local/lib
)

# Setting up test folder.
file(MAKE_DIRECTORY ${OSGi_BINARY_DIR}/bin/bundles)
file(MAKE_DIRECTORY ${OSGi_BINARY_DIR}/bin/cache)
file(MAKE_DIRECTORY ${OSGi_BINARY_DIR}/bin/tmp)
file(MAKE_DIRECTORY ${OSGi_BINARY_DIR}/test/deployment)
configure_file(Report.xsl ${OSGi_BINARY_DIR}/bin/Report.xsl COPYONLY)
configure_file(osgi.ini   ${OSGi_BINARY_DIR}/bin/osgi.ini   COPYONLY)

# Tests.
enable_testing()
add_test(
    NAME                Library
    WORKING_DIRECTORY   ${OSGi_BINARY_DIR}/bin
    COMMAND             valid
)
add_test(
    NAME                Install
    WORKING_DIRECTORY   ${OSGi_BINARY_DIR}
    COMMAND             ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=/ -P cmake_install.cmake
)
add_test(
    NAME                Use
    WORKING_DIRECTORY   ${OSGi_BINARY_DIR}/test/deployment
    COMMAND             ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
                                         -DWITH_OSGi_VERSION=${OSGi_VERSION}
                                         ${OSGi_SOURCE_DIR}/test/deployment
)
add_test(
    NAME                Build
    COMMAND             ${CMAKE_COMMAND} --build ${OSGi_BINARY_DIR}/test/deployment
)
add_test(
    NAME                Launcher
    WORKING_DIRECTORY   ${OSGi_BINARY_DIR}/bin
    COMMAND             osgi-start
)

# The check command.
add_custom_target(check COMMAND DESTDIR=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CTEST_COMMAND} DEPENDS OSGi++ osgi-packager osgi-start valid)
